package part14;

import java.util.*;

/**
 * @author wcj
 * @Date 2021/5/26 15:36
 * @Version 1.0
 */
public class Part148 {
    private static List<Class<? extends BaseClass>> types = Collections.unmodifiableList(Arrays.asList(BaseClass.class, OneClass.class, TwoClass.class));
    private static Map<Object, Object> map = new HashMap<>(3);

    /**
     * 相比于instanceof关键字的不灵活性，我们可以使用isInstance()函数来判断类型
     *
     * @param args
     */
    public static void main(String[] args) {
        map.put(new BaseClass(), new BaseClass());
        map.put(new OneClass(), new OneClass());
        map.put(new TwoClass(), new TwoClass());
        for (Class<? extends BaseClass> type : types) {
            System.out.println(type);
            for (Object o : map.keySet()) {
                if (type.isInstance(o)) {
                    System.out.println(map.get(o).getClass().getSimpleName());
                }
            }
        }
    }
}

class BaseClass {
}

class OneClass extends BaseClass {
}

class TwoClass extends BaseClass {
}
